package com.db.concurrency.tracker;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * @author Alexander Kotov (kotov.alex.22@gmail.com)
 */
public class DelegatedThreadSafetyTracker {
    private final ConcurrentMap<String, ImmutablePoint> map;
    private final Map<String, ImmutablePoint> mapWrapper;

    public DelegatedThreadSafetyTracker(Map<String, ImmutablePoint> map) {
        this.map = new ConcurrentHashMap<String, ImmutablePoint>(map);
        mapWrapper = Collections.unmodifiableMap(this.map);
    }

    public ImmutablePoint getLocation(String id) {
        return map.get(id);
    }

    public void setLocation(String id, ImmutablePoint p) {
         map.put(id, p);
    }

    public Map<String, ImmutablePoint> getLocations() {
        return mapWrapper;
    }
}
